<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .el-page-header__content{
            color: white;
            font-weight: bold;
        }

        body{
            margin: 0;/*去掉外边距*/
            background-image: url("imgs/reg_img.png");
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-size: cover;
        }
    </style>
</head>
<body>
<div id="app" style="opacity: 0.75;font-weight: bold">

    <el-page-header style="background-color: #0095d7;
            color: white;line-height: 60px" @back="goBack" content="添加商品">
    </el-page-header>
    <el-card style="width: 600px;height: 700px;margin: 0 auto">
        <el-form label-width="80px">
            <el-form-item label="公告标题" >
                <el-input type="text" v-model="p.price"></el-input>
            </el-form-item>
            <el-form-item label="公告内容" :rows="4">
                <el-input type="text" v-model="p.oldPrice"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="success" @click="insert()">添加公告</el-button>
            </el-form-item>
        </el-form>
    </el-card>


</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function() {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                p:{
                    title:"",
                    price:"",
                    oldPrice:"",
                    saleCount:"",
                    num:"",
                    categoryId:"",
                    url:""
                },
                categoryArr:[]
            }
        },
        methods:{
            insert(){
                if (v.p.url==""){
                    v.$message.error("请选择上传的图片!");
                    return;
                }
                //发出添加商品的请求
                axios.post("/product/insert",v.p).then(function (response) {
                    location.href="/admin.html";

                })
            },
            handleSuccess(response,file,fileList){
                //response代表服务器响应的图片路径
                v.p.url = response;
            },
            goBack(){
                history.back();//返回上一页面
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
                //发出删除图片的请求
                axios.get("/remove?url="+v.p.url).then(function () {
                    v.$message("服务器图片删除完成");
                    v.p.url="";
                })
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            }
        },
        created:function (){
            //发请求获取分类数据
            axios.get("/category/select").then(function (response) {
                v.categoryArr = response.data;

            })
        }
    })
</script>
</html>